﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alta.Class
{

    public enum CommandMode
    {
        NONE,WAIT,RUN
    }
    public class Command
    {
        public string name { get; set; }
        public string content { get; set; }
        public int id { get; set; }
        private CommandMode _mode = CommandMode.NONE;
        public CommandMode mode
        {
            get
            {
                return _mode;
            }
            set
            {
                _mode = value;
                if (this._mode == CommandMode.RUN)
                {
                    this.changeStatus();
                }
            }
        }

        private void changeStatus()
        {
            if (this.mode == CommandMode.RUN)
            {
                mysql_helpper.setStatus(this.id, false);
            }
            else
            {
                mysql_helpper.setStatus(this.id, true);
            }
        }

        public static Command Parse(MySqlDataReader reader)
        {
            if (reader == null)
            {
                return null;
            }

            Command cmd = null;

            while (reader.Read())
            {
                if (!reader.IsDBNull(0))
                {
                    if (cmd == null)
                        cmd = new Command();
                    cmd.name = reader.GetString(0);
                }
                if (!reader.IsDBNull(1))
                {
                    if (cmd == null)
                        cmd = new Command();
                    cmd.name = reader.GetString(1);
                }
            }
            return cmd;
        }

    }
}
